<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <script>
        /**
         * Promise
         * 1、主要用于异步计算
           2、可以将异步操作队列化，按照期望的顺序执行，返回符合预期的结果
           3、可以在对象之间传递和操作promise，帮助我们处理队列
        */

            // promise获取奶茶的方法
        function gettea(){
            // resolve可以将异步的数据传递出来
            return new Promise(function(resolve){
                setTimeout(() => {
                    resolve('喝奶茶')
                }, 500);
            })
          
        }
        
        function getHotPot(){
            return new Promise(function(resolve){
                setTimeout(() => {
                    resolve('吃火锅')
                }, 1000);
            })
        }

        function drinkSoda(){
            return new Promise(function(resolve){
                setTimeout(() => {
                    resolve('喝汽水')
                }, 3000);
            })
        }
       
        // 先喝汽水，再喝奶茶，最后吃火锅
        drinkSoda().then((res)=>{
            // console.log(res)
            return gettea() //可以返回一个接下来还想调的promise对象
        }).then((res)=>{
            // console.log(res)
            return getHotPot()
        }).then((res)=>{
            // console.log(res)
        })

        // 用async函数实现  
        async function getData(){
       // await 后面加一个promise对象就可以直接获取resolve传递出来的异步数据
           let drink = await drinkSoda()
           console.log(drink)
           let tea = await gettea()
           console.log(tea)
           let hotPot = await getHotPot()
           console.log(hotPot)
        }
        getData()
        
        let msg ='hello'
        let newMsg=msg.split("").reverse().join("");
        let arr = [1,2,3,1,5,6,8]

        console.log(newMsg)
        console.log(arr.slice(0,-1))
        var fruits = ["Banana", "Orange", "Apple", "Mango"];
        fruits.splice(2,0,"Lemon","Kiwi")
        console.log(fruits)

    </script>
</body>
</html>